#!/usr/bin/env python
# encoding: utf-8
# @author: Lin Han
# @contact: voldemort22@126.com
# @file: 20210617.py
# @time: 2021/6/17 13:55
# @desc:
from utils.mongo_tools import retrieve_all_mongo_values, update_mongo_value
from utils.utils import read_json
from views.configs import HISTORY_PART_COLLECTION

# history_part_config = read_json("data/export_data/config_20210617.json")[0]

history_part = retrieve_all_mongo_values(
    {},
    collection_name=HISTORY_PART_COLLECTION,
)

history_part_config = read_json("data/export_data/part_type_20210617.json5")

history_part_config_dict = dict(zip(
    [i["name"] for i in history_part_config],
    [i["number"] for i in history_part_config],
))

for i in history_part:
    if i["tag"]["partType"] != "":
        key = i["tag"]["partType"].split("->")[-1]
        print(key)
        i["tag"]["partType"] = history_part_config_dict[key]
        print(i["tag"])

for i in history_part:
    if "version" not in i["tag"].keys():
        i["tag"]["version"] = "暂无"

for i in history_part:
    update_mongo_value(
        filter_condition={"number": i["number"]},
        new_value={"$set": i},
        collection_name=HISTORY_PART_COLLECTION
    )